package main

import (
	"io"
	"net/http"
	"os"
)

type OurCustomTransport struct {
	//Transport用于确定HTTP请求的创建机制。
	Transport http.RoundTripper
}

func (t *OurCustomTransport) transport() http.RoundTripper {
	if t.Transport != nil {
		return t.Transport
	}
	return http.DefaultTransport
}
func (t *OurCustomTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	//处理一些事情
	//发起http请求
	//添加一些域到req.hreader中
	return t.transport().RoundTrip(req)
}
func (t *OurCustomTransport) Client() *http.Client {
	return &http.Client{Transport: t}
}
func main() {
	t := &OurCustomTransport{}
	c := t.Client()
	resp, err := c.Get("http://example.com")
	if err != nil {
		return err.Error()
	}
	io.Copy(os.Stdout, resp.Body)
}
